<template>
	<div class="app-container">
		<!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
			<el-form-item label="菜单名称" prop="menuName">
				<el-input v-model="queryParams.menuName" placeholder="请输入菜单名称" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="状态" prop="status">
				<el-select v-model="queryParams.status" placeholder="菜单状态" clearable>
					<el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form> -->

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">展开/折叠</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-if="refreshTable" v-loading="loading" :data="menuList" row-key="ouid"
			:default-expand-all="isExpandAll" :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
			<el-table-column prop="ouname" label="菜单名称" :show-overflow-tooltip="true"></el-table-column>
			<!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['system:menu:edit']">修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)"
						v-hasPermi="['system:menu:add']">新增</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['system:menu:remove']">删除</el-button>
				</template>
			</el-table-column> -->
		</el-table>
	</div>
</template>

<script>
	import { orgList } from "@/api/identity/identity"
	import Treeselect from "@riophae/vue-treeselect";
	import "@riophae/vue-treeselect/dist/vue-treeselect.css";
	import IconSelect from "@/components/IconSelect";

	export default {
		name: "Menu",
		dicts: ['sys_show_hide', 'sys_normal_disable'],
		components: {
			Treeselect,
			IconSelect
		},
		data() {
			return {
				// 遮罩层
				loading: true,
				// 显示搜索条件
				showSearch: true,
				// 菜单表格树数据
				menuList: [],
				// 菜单树选项
				menuOptions: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 是否展开，默认全部折叠
				isExpandAll: true,
				// 重新渲染表格状态
				refreshTable: true,
				// 查询参数
				queryParams: {
					menuName: undefined,
					visible: undefined
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {
					menuName: [{
						required: true,
						message: "菜单名称不能为空",
						trigger: "blur"
					}],
					orderNum: [{
						required: true,
						message: "菜单顺序不能为空",
						trigger: "blur"
					}],
					path: [{
						required: true,
						message: "路由地址不能为空",
						trigger: "blur"
					}]
				}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询菜单列表 */
			getList() {
				this.loading = true;
				orgList(this.queryParams).then(response => {
					console.log('menuList1', response.data);
					this.menuList = this.handleTree(response.data, "ouid", "parentOUID");
					console.log('menuList2', this.menuList);
					this.loading = false;
				});
			},

			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					menuId: undefined,
					parentId: 0,
					menuName: undefined,
					icon: undefined,
					menuType: "M",
					orderNum: undefined,
					isFrame: "1",
					isCache: "0",
					visible: "0",
					status: "0"
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			/** 展开/折叠操作 */
			toggleExpandAll() {
				this.refreshTable = false;
				this.isExpandAll = !this.isExpandAll;
				this.$nextTick(() => {
					this.refreshTable = true;
				});
			}
		}
	}
</script>